package com.pactera.demo.base.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;

import java.util.Collection;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.social.security.SocialUserDetails;

/**
 * <p>
 * 登录信息表
 * </p>
 *
 * @author mybatis.plus
 * @since 2020-02-27
 */
@Data
@ToString
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_login_user")
public class LoginUser implements Serializable,UserDetails, SocialUserDetails {

    private static final long serialVersionUID = 1L;

    /**
     * 编号
     */
    @TableId(value = "ID", type = IdType.UUID)
    private String id;

    /**
     * 登录名
     */
    @TableField("LOGIN_NAME")
    private String loginName;

    /**
     * 密码
     */
    @TableField("PASSWORD")
    private String password;

    /**
     * 绑定的邮箱
     */
    @TableField("MAIL")
    private String mail;

    /**
     * 绑定的手机号
     */
    @TableField("MOBILE")
    private String mobile;

    /**
     * 关联用户个人信息表
     */
    @TableField("USER_ID")
    private String userId;

    /**
     * 账号未过期
     */
    @TableField("ACCOUNT_NON_EXPIRED")
    private boolean accountNonExpired = true;

    /**
     * 账号未锁定
     */
    @TableField("ACCOUNT_NON_LOCKED")
    private boolean accountNonLocked = true;

    /**
     * 密码未过期
     */
    @TableField("CREDENTIALS_NON_EXPIRED")
    private boolean credentialsNonExpired = true;

    /**
     * 数据可用
     */
    @TableField("ENABLED")
    private boolean enabled = true;

    /**
     * 创建日期 默认为当前时间
     */
    @TableField("CREATE_DATE")
    private Date createDate;

    public LoginUser(String loginName, String password) {
        this.loginName = loginName;
        this.password = password;
    }

    @TableField(exist = false)
    private User user;

    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;


    @Override
    public String getUsername() {
        return this.loginName;
    }
}
